namespace nu.Model
{
    using System.Collections.Generic;

    public class PackageCatalogService
    {
        private readonly ILocalPackageRepository _repository;

        public PackageCatalogService(ILocalPackageRepository repository)
        {
            _repository = repository;
        }

        public IEnumerable<Package> GetInstalledPackages()
        {
            return _repository.FindAll();
        }

        public void Uninstall(string packageName)
        {
            Package thePackage = _repository.Find(packageName);
            if(thePackage == null)
            {
                throw new PackageNotFoundException(packageName);
            }
            _repository.Delete(thePackage);
        }

        public Package FindPackage(string packageName)
        {
            Package thePackage = _repository.Find(packageName);
            if(thePackage == null)
            {
                throw new PackageNotFoundException(packageName);
            }
            return thePackage;
        }
    }
}